import _fetch from '@/Utils/Fetch';
import {
  mallManagement,
  userManagement
} from '@/Utils/Urls';

// 商家寄件
export const managerBorderOfficialThunk = (data) => () => new Promise((resolve, reject) => {
  _fetch({
    url: mallManagement.managerBorderOfficial,
    data,
    type: 'post',
    isJson: true
  }).then(res => {
    if (res && res.status === 200) {
      resolve(res)
    } else {
      reject()
    }
  })
})

// 商家发货
export const queryShipAddressIdThunk = () => () => new Promise((resolve, reject) => {
  _fetch({
    url: userManagement.queryShipAddressId,
  }).then(res => {
    if (res && res.status === 200) {
      resolve(res)
    } else {
      reject()
    }
  })
})

// 商家更新订单状态
export const managerUpdateOrderStatusThunk = (orderId, orderStatus) => () => new Promise((resolve, reject) => {
  const formdata = new FormData()
  formdata.append('orderId', orderId)
  formdata.append('orderStatus', orderStatus)
  _fetch({
    url: mallManagement.managerUpdateOrderStatus,
    type: 'post',
    data: formdata
  }).then(res => {
    if (res && res.status === 200) {
      resolve(res)
    } else {
      reject()
    }
  })
})


export const getExpressOnPassageThunk = (orderId) => () => new Promise((resolve, reject) => {
  _fetch({
    url: mallManagement.getExpressOnPassage + `/${orderId}`,
    type: 'get',
  }).then(res => {
    if (res && res.status === 200) {
      resolve(res)
    } else {
      reject()
    }
  })
})